<?php
// This file define 3 parts:
// 1. Horizontal tab menu
// 2. Multi-language
// 3. Search form
// 
// Tab menu is placed on the same layer of the parent (same 'z-index').
// Others placed on higher layer (higher 'z-index').
?>
<?php
$cs = Yii::app()->getClientScript();
$baseUrl = Yii::app()->request->baseUrl;
$cs->registerCssFile($baseUrl . '/css/cart/bootstrap.min.css');
$cs->registerScriptFile($baseUrl . '/js/jquery/bootstrap.min.js', CClientScript::POS_END);
$cs->registerScriptFile($baseUrl . '/js/jquery/jquery.cookie.js', CClientScript::POS_END);
$cs->registerScriptFile($baseUrl . '/js/jquery/jquery.easing.1.3.js', CClientScript::POS_END);
$cs->registerScriptFile($baseUrl . '/js/jquery/jquery.json-2.3.min.js', CClientScript::POS_END);
$cs->registerScriptFile($baseUrl . '/js/jquery/jquery.quicksand.js', CClientScript::POS_END);
$cs->registerScriptFile($baseUrl . '/js/cart.js', CClientScript::POS_END);
?>

<ul class="tabs">
    <?php
    // 1. Horizontal tab menu.
    // There are vertical seperators between tabs.
    // Categories tab are dynamic, others are static.

    /**
     * 
     */
    function selectTab($tab = '', $cat = 'none') {
        // shorthand of Yii::app()->request->url
        $url = Yii::app()->request->url;

        // TRUE in case if the tab will be selected (have class 'selected')
        // otherwise FALSE
        $selected = false;

        switch ($tab) {
            case '':
                // Home page is request. By default, home URL is also application
                // URL, so this does not contain the prefix '.html'.
                $selected = strpos($url, '.html') === false;
                break;
            case 'news':
            case 'post':
            case 'about':
            case 'contact':
            case 'support':
            case 'policy':
            case 'login':
            case 'logout':
                // Requested page may be 'news', 'post', 'about' or 'contact' page
                $selected = strpos($url, $tab) !== false;
            default:
                break;
        }

        if ($selected) {
            echo 'selected';
        }
    }
    ?>
    <li class="tab-item icons first <?php selectTab() ?>">
        <a class="" href="<?php echo Yii::app()->homeUrl ?>">
            <div class="gradient">
                <div class="text">
                    <?php echo Yii::t('default', 'Home') ?>
                </div>
            </div>
        </a>
    </li><!-- home -->

    <li class="separator"></li>

    <?php
    // News tab: list all news
    // Note that ~/post/list is rewrite to ~/posts.
    ?>
    <li class="tab-item icons <?php selectTab('post') ?>">
        <a class="" href="<?php echo $this->createUrl('post/list') ?>">
            <div class="gradient">
                <div class="text">
                    <?php echo Yii::t('default', 'News') ?>
                </div>
            </div>
        </a>
    </li><!-- news -->

    <li class="separator"></li>

    <?php
    // About tab.
    // Note that ~/site/about is rewrite to ~/about.
    ?>
    <li class="tab-item icons <?php selectTab('about') ?>">
        <a class="" href="<?php echo $this->createUrl('site/about') ?>">
            <div class="gradient">
                <div class="text">
                    <?php echo Yii::t('default', 'About Us') ?>
                </div>
            </div>
        </a>
    </li><!-- about -->

    <li class="separator"></li>

    <?php
    // Contact tab.
    // Note that ~/site/contact is rewrite to ~/contact.
    ?>
    <li class="tab-item icons <?php selectTab('contact') ?>">
        <a class="" href="<?php echo $this->createUrl('site/contact') ?>">
            <div class="gradient">
                <div class="text">
                    <?php echo Yii::t('default', 'Contact') ?>
                </div>
            </div>
        </a>
    </li><!-- contact -->

    <li class="separator"></li>

    <?php
    // Buying support tab.
    // Note that ~/site/support is rewrite to ~/support.
    ?>
    <li class="tab-item icons <?php selectTab('support') ?>">
        <a class="" href="<?php echo $this->createUrl('site/support', array('type' => 'purchase')) ?>">
            <div class="gradient">
                <div class="text">
                    <?php echo Yii::t('default', 'Support order') ?>
                </div>
            </div>
        </a>
    </li><!-- buying support -->

    <li class="separator"></li>

    <?php
    // General policy tab.
    // Note that ~/site/policy is rewrite to ~/policy.
    ?>
    <li class="tab-item icons <?php selectTab('policy') ?>">
        <a class="" href="<?php echo $this->createUrl('site/policy', array('type' => 'warranty')) ?>">
            <div class="gradient">
                <div class="text">
                    <?php echo Yii::t('default', 'General policy') ?>
                </div>
            </div>
        </a>
    </li><!-- General policy -->

    <li class="separator"></li>

    <li style="float: right; list-style: none;">
        <a id="show_cartBtn" class="btn btn-warning" data-toggle="modal" href="#cart_holder">
            0 sản phẩm trong 
            <i class="icon-shopping-cart"></i>
            <strong></strong>
        </a>
    </li><!-- Cart -->

</ul><!-- tabs -->

<div class="search-form">
    <?php
    // 3. Search form.
    // This is in higher layer of its container (tab-nav).
    ?>
    <div>
        <?php
        $productSearch = new Search;
        $form = $this->beginWidget('CActiveForm', array(
            'id' => 'search-form',
            'method' => 'get',
            'action' => array('product/search'),
            'enableAjaxValidation' => true,
            'htmlOptions' => array('accept-charset' => 'UTF-8'), //, 'accept-charset' => 'UTF-8'
                ));
        echo $form->errorSummary($productSearch);

        echo $form->textField($productSearch, 'keyWord', array('placeholder' => Yii::t('default', 'Type to search product')));
        echo CHtml::submitButton(Yii::t('default', 'Search'), array('id' => 'seach-button'));
        $this->endWidget();
        ?>
    </div>
    <style type="text/css">
        form{margin: 0px;}
    </style>
    <script type="text/javascript">
        jQuery(function() {
            var userAgent = navigator.userAgent.toString().toLowerCase();
            if (userAgent.indexOf('msie') != -1) {
                var inputtext = jQuery('.search-form input[type=text]');
                var changed = false;
                inputtext.val(inputtext.attr('placeholder'));

                inputtext.keyup(function() {
                    if (inputtext.val() != '') {
                        changed = true;
                    } else {
                        changed = false;
                    }
                });
            
                inputtext.focusin(function() {
                    inputtext.css('color', '#000');
                    if (!changed) {
                        inputtext.val('');
                    }
                }).focusout(function() {
                    if (!changed || inputtext.val() == '') {
                        inputtext.css('color', '#888');
                        inputtext.val(inputtext.attr('placeholder'));
                    }
                });
            
                jQuery('#seach-button').click(function() {
                    if (!changed) {
                        inputtext.val('');
                    }
                });
            }
        });
    </script>
</div><!-- search form -->

<div class="login-form">
    <ul style="list-style: none;">
        <?php if (Yii::app()->user->isGuest): ?>
            <li>
                <a href="<?php echo $this->createUrl('site/register') ?>">
                    <?php echo Yii::t('default', 'Sign up') ?>
                </a>
            </li><!-- Register -->
            
            <li>
                <a href="<?php echo $this->createUrl('site/login') ?>">
                    <?php echo Yii::t('default', 'Sign in') ?>
                </a>
            </li><!-- Login -->
        <?php endif; ?>
        <?php if (!Yii::app()->user->isGuest): ?>
            <li>
                <a style="text-decoration: none;" href="javascript:void(0);">
                    <?php echo Yii::t('default', 'Hi ') . ' ' . Yii::app()->user->name; ?>
                </a>
            </li><!-- information -->
            
            <li>
                <a href="<?php echo $this->createUrl('site/logout') ?>">
                    <?php echo Yii::t('default', 'Sign out') ?>
                </a>
            </li><!-- sign out -->

        <?php endif; ?>
    </ul>
</div><!-- login form -->
<!-- Shopping Cart Modal Holder -->
<div class="modal hide fade" id="cart_holder">
    <div class="modal-header"> <a class="close" data-dismiss="modal">x</a>
        <h3>Giỏ hàng</h3>
    </div>
    <div class="modal-body"> 
        <!--  Cart Data -->
        <table class="table">
            <thead>
                <tr>
                    <th>Mã SP</th>
                    <th>Tên SP</th>
                    <th>Giá</th>
                    <th>Số lượng</th>
                    <th>Chiết khấu (%)</th>
                    <th>Tổng tiền</th>
                </tr>
            </thead>
            <tbody id="shopping_cart_data">
                <tr>
                    <td colspan="6"><div class="alert alert-info">Giỏ hàng rỗng!</div></td>
                </tr>
            </tbody>
        </table>
        <!--  /Cart Data --> 
    </div>
    <div class="modal-footer"> 
        <!--  Action Buttons -->
        <div id="shopping_cart_total" class="alert alert-info tar"> 0 sản phẩm </div>
        <div> <a id="checkout_submit_order" class="btn btn-warning" href="<?php echo $this->createUrl('user/checkLogin') ?>">Đặt hàng</a> <a href="#" class="btn" data-dismiss="modal">Tiếp tục mua</a> </div>
        <!--  /Action Buttons --> 
    </div>
</div>
<!-- /Shopping Cart Modal Holder --> 

